#include <IRremote.h>
#include <Timer.h>
#include "ArcDefs.h"
#include "ArcMotor.h"
#include "ArcUtility.h"

const int RECV_PIN = 8;

Timer timer;

IRrecv irrecv(RECV_PIN);
decode_results results;

char lastCmd = ARC_MOTOR_CMD_STOP;

ArcMotor motor;

void setup()
{
	Serial.begin(9600);
	irrecv.enableIRIn(); // Start the receiver

	motor.Initialize(MOTOR_PIN_L_1, MOTOR_PIN_L_2, MOTOR_PIN_R_1, MOTOR_PIN_R_2);
}

void loop()
{
	if (irrecv.decode(&results))
	{
		Serial.println(results.value, HEX);

		switch (results.value)
		{
			case 0xFFC837:
				motor.Run(ARC_MOTOR_CMD_FORWARD);
				break;
			case 0xFFE817:
				motor.Run(ARC_MOTOR_CMD_BACKWARD);
				break;
			case 0xFFA857:
				motor.Run(ARC_MOTOR_CMD_TURN_LEFT);
				break;
			case 0xFFB847:
				motor.Run(ARC_MOTOR_CMD_TURN_RIGHT);
				break;
			default:
				if (0xFFFFFFFF != results.value)
				{
					motor.Run(ARC_MOTOR_CMD_STOP);
				}
				break;
		}

		irrecv.resume(); // Receive the next value
	}
}
